package com.tangyee.person_risk_assessment.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tangyee.R;

import com.tangyee.person_risk_assessment.data.UserHeight;

import top.defaults.view.PickerView;
import top.defaults.view.PickerViewDialog;

public class UserHeightPickerDialog extends BaseDialogFragment {

    private PickerView pickerView;

    public static UserHeightPickerDialog newInstance(int type, ActionListener actionListener) {
        return BaseDialogFragment.newInstance(UserHeightPickerDialog.class, type, actionListener);
    }

    @Override
    public Dialog createDialog(Bundle savedInstanceState) {
        PickerViewDialog dialog = new PickerViewDialog(getActivity());
        dialog.setContentView(R.layout.dialog_height_picker);

        pickerView = dialog.findViewById(R.id.pickerView);
        // 为身高picker 初始化数据
        pickerView.setItems(UserHeight.getUserHeightList(), null);
        // 设置picker 的初始item的位置是中间的
        pickerView.setSelectedItemPosition(UserHeight.getUserHeightList().size() / 2);
        // 身高单位的 picker
        PickerView pickerViewUnit = dialog.findViewById(R.id.pickerView_unit);
        pickerViewUnit.setItems(UserHeight.getUserHeightUnit(), null);

        attachActions(dialog.findViewById(R.id.done), dialog.findViewById(R.id.cancel));
        return dialog;
    }

    @Nullable
    @Override
    public View createView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_height_picker, container, false);

        pickerView = view.findViewById(R.id.pickerView);
        // 为身高picker 初始化数据
        pickerView.setItems(UserHeight.getUserHeightList(), null);

        attachActions(view.findViewById(R.id.done), view.findViewById(R.id.cancel));
        return view;
    }

    public UserHeight getSelectedItem() {
        return pickerView.getSelectedItem(UserHeight.class);
    }
}
